package com.demo.designmode.iterator;

import java.util.List;

/**
 * @Author: jxm
 * @Description: 具体迭代器角色类
 * @Date: 2023-12-12 14:40
 * @Version: 1.0
 */
public class StudentIteratorImpl implements StudentIterator{
    //存储迭代对象
    private List<Student> list;
    //用来记录遍历时的位置
    private int position = 0;

    public StudentIteratorImpl(List<Student> list) {
        this.list = list;
    }

    @Override
    public boolean hasNext() {
        return position < list.size();
    }

    @Override
    public Student next() {
        //从集合获取指定位置的元素
        Student student = list.get(position);
        position++;
        return student;
    }
}
